The present invention relates to locks, and particularly to a magnetic lock which is suitable for doors of various specifications. Furthermore, the magnetic lock of the present invention has an open mode operated in power-on state and a close mode operated in power-off state. Moreover, a pin serves to achieve the object of function setting. The magnetic lock of the present invention has the function of a mechanical lock and an electronic lock. The structure of the magnetic lock is simple and easy in maintenance with a longer lifetime and lower manufacturing cost.